package com.inibb.app.exception;

import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

public class ServiceVLDException extends BindException{

	public ServiceVLDException(BindingResult bindingResult) {
		super(bindingResult);
	}
	public ServiceVLDException(Object target, String objectName) {
		super( target, objectName );
	}
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public String getPrettyMessage(){
		StringBuilder sb = new StringBuilder();
		if(this.hasErrors()){
			for(Object o: this.getAllErrors()){
				ObjectError oe = (ObjectError)o;
				sb.append(oe.getObjectName() +" has error: msg->"+oe.getDefaultMessage()+", arguments->"+oe.getArguments());
				sb.append("\n");
			}
		}
		return sb.toString();
	}
}
